pp108 : Uploading a File to a Service

Uploading a File to a Service

This topic describes the procedure to create a HTML page for uploading a file to a service.

At times, you may have to upload files to a service while it is running, through a Web browser. To support this process, a HTML page is required that is programmed to upload the required file. Process Platform provides you the required component to design such a page.

The componentupload.htm internally uses a template, which is a HTML page. The component takes the file name and the contents of the page. Additionally, it also takes the request SOAP message for the service to which the file will be uploaded, and submits it to a Java class called Upload.wcp. This Java class replaces the keywords Upload:FileName1 and Upload:FileContent1 in the request SOAP Message with the actual file name and the file content, and sends the request message to the Process Platform Gateway. Process Platform Web Gateway then sends it to the appropriate service. The file is successfully uploaded to the intended service.


Caution:Upload Gateway stores the uploaded files in a shared directory and passes the directory name to the service container to process the request. The shared directory is refered by the com.eibus.web.tools.upload.UploadWritePath wcp.property. It is possible that a hacker can continuously send upload requests where no service container is available to handle them. In such a case, the disk space will be full in no time. To avoid such a scenario, it is strongly recommended that you specify a size-limit on the shared directory.

There are certain situations where you have to upload files which are large in size. In such situations, instead of uploading a file directly you can specify the path of the file in the
Upload:FilePath property in the SOAP request. When this property is used, the uploaded file is stored at a temporary location given in the property 'com.eibus.web.tools.upload.UploadWritePath' present in the wcp.properties file and the SOAP Request is sent to the SOAP service with the location of the temporary file.
Note: The user in whose context the Webserver runs should have write permissions on the specified directory. Uploading files which are large in size will lead to high consumption of memory. The hardware configuration of your computer determines if the file that you are uploading is large. Certain computers can accomodate a file of size 50 MB but some computers may not be able to handle a file of size 4 MB too. Therefore, you can use this property depending on the hardware configuration of your computer.
The SOAP service can read the file from the temporary location.

Note: The SOAP response from the gateway contains details of the file to be uploaded. You must know the exact element within the SOAP response that contains the details.
The following figure illustrates the way the upload process works.


  1. Create a HTML page, fulfilling the following requirements:
    1. Add the script <script type=text/javascript src='/cordys/wcp/application.js'></script> to the page.
    2. Add the upload component to the page as shown in the code:
      <div cordysType="wcp.library.util.Upload" id="uploader" encode="true" showStatus= "true" request = requestSting.XMLDocument onupload = "onUploadHandler ()"/>

  2. Create a SOAP message that will be sent to the service, and add it to the page as shown in the example below:
    <script id="requestString" type="cordys/xml">
        <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
            <SOAP:Body>
                <UpdateXMLObject xmlns="http://schemas.cordys.com/1.0/xmlstore">
                    <tuple key="Upload:FileName1">
                        <new>Upload:FileContent1</new>
                    </tuple>
                </UpdateXMLObject>
            </SOAP:Body>
        </SOAP:Envelope>
    </script>
    

    Note: In the SOAP Message, the keywords Upload:FileName 1 and Upload:FileContent 1 are included in places where the file name and file content are present. Also, the keyword Upload:FileContent should not be an attribute of an element in the SOAP message. If more than one file needs to be uploaded, the file count property of the component can be set to the number of files required. In such a case, the SOAP message should also be appropriately updated to include the keywords Upload:FileName<n>andUpload:FileContent<n>(where 'n' represents the filecount) to include all the files.

  3. Add the browse Web service operation to the page. This Web service operation provides the functionality for browsing the files. It can be called as many times as the number of files to be uploaded, using file numbers as parameters.
  4. Add the uploadFile Web service operation to the page. Developing the HTML page is complete.
  5. Create a shortcut. For more information on creating a shortcut, refer to Creating a Shortcut using URL.
    Note: The URL for creating the shortcut is the URL for accessing the HTML page.
    The HTML page to upload a file from a service is created.
    Note: For more information on uploading a file to a service, refer to Upload (AJAX Toolkit API).

Related reference

Upload